home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / tcp_ip / ka9q / kit_src / execute.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-03  |  2.1 KB  |  72 lines

  1. /*    (C) Copyright 1991 Dave Fritsche (wb8zxu), All Rights Reserved.
  2.  * 
  3.  *    Redistribution and use in source and binary forms are permitted for
  4.  *    non-commercial use, provided that the above copyright notice and this
  5.  *    paragraph are duplicated in all such forms.  THIS SOFTWARE IS PROVIDED
  6.  *    ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  7.  *    WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND
  8.  *    FITNESS FOR A PARTICULAR PURPOSE.
  9.  */
  10. #include <stdio.h>
  11. #include <dir.h>
  12. #include "screen.h"
  13.  
  14. execute(fnm)
  15. char fnm[];
  16. {
  17.     int cwd;
  18.     FILE *fp;
  19.     unsigned char buf[128], drive[MAXDRIVE], dir[MAXDIR], fname[MAXFILE];
  20.     unsigned char ext[MAXEXT], curdir[MAXDIR], newdir[MAXDIR], slash[2];
  21.  
  22.     cwd = getdisk();
  23.     getcurdir(0, curdir);
  24.     fnsplit(path, drive, dir, fname, ext);
  25.     drive[0] = toupper(drive[0]);
  26.     sprintf(newdir, "%s%s", dir, fname);
  27.     if (strlen(newdir) == 0)
  28.         sprintf(newdir, "\\");
  29.  
  30.     if ( strlen(curdir) < 1 )
  31.         sprintf(buf, "%c:\\%s", (cwd+'A'), fnm);
  32.     else
  33.         sprintf(buf, "%c:\\%s\\%s", (cwd+'A'), curdir, fnm);
  34.  
  35.     if ( (fp = fopen(buf, "r")) == NULL )
  36.     {
  37.         if (debug)
  38.             printf("***> \"%s\" (%s) not present\n",
  39.                     fnm, buf);
  40.         return(0);
  41.     }
  42.     fclose(fp);
  43.  
  44.     if ( strlen(curdir) < 1 )
  45.         sprintf(buf, "%c:\\%s %c: \\ %c: %s \\", (cwd+'A'),
  46.              fnm, (cwd+'A'), drive[0], newdir);
  47.     else
  48.         sprintf(buf, "%c:\\%s\\%s %c: \\%s\\ %c: %s \\%s", (cwd+'A'),
  49.             curdir, fnm, (cwd+'A'), curdir, drive[0], newdir,
  50.             curdir);
  51.  
  52.     if (ka9q)            strcat(buf, " ka9q");
  53.     else                strcat(buf, " noka9q");
  54.     if (g1emm)            strcat(buf, " g1emm");
  55.     else                strcat(buf, " nog1emm");
  56.     if (bm)                strcat(buf, " bm");
  57.     else                strcat(buf, " nobm");
  58.     if (netnews)            strcat(buf, " netnews");
  59.     else                strcat(buf, " nonetnews");
  60.  
  61.     if (debug)
  62.         printf("***> execute:  %s\n", buf);
  63.     if ( system(buf) != 0 )
  64.     {
  65.         printf("\nCan't seem to execute the batch file \"%s\"\n", buf);
  66.         printf("The most likely reason is that COMMAND.COM isn't ");
  67.         printf("where the \"COMSPEC\"\n");
  68.         printf("environment variable says it is.\n\n");
  69.         exit(1);
  70.     }
  71. }
  72.